package com.lhd_gm.scheduledtasksystem.job;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.lhd_gm.scheduledtasksystem.pojo.ShellTask;
import com.lhd_gm.scheduledtasksystem.utils.ShellExecutor;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;

public class ShellJob implements Job {
    public void execute(JobExecutionContext jobExecutionContext) {
        JobDataMap dataMap = jobExecutionContext.getJobDetail().getJobDataMap();
        String stJson = dataMap.getString("shellConfig");
        String shellPath = dataMap.getString("shellPath");
        ObjectMapper objectMapper = new ObjectMapper();

        try {
            ShellTask shellTask = (ShellTask)objectMapper.readValue(stJson, ShellTask.class);
            ShellExecutor.executeScript(shellTask, shellPath);
            System.out.println("脚本执行成功！");
        } catch (Exception var8) {
            System.out.println("脚本执行失败！");
        }

    }
}
